﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TFit
{
    public partial class NewUserDialog : Form
    {
        User user_;

        /// <summary>
        /// Initializes a new instance of the <see cref="NewUserDialog"/> class.
        /// </summary>
        public NewUserDialog()
        {
            InitializeComponent();
        }
        /// <summary>
        /// Пользователь (getter)
        /// </summary>
        /// <returns>Возвращает ссылку на нового пользователя</returns>
        public User GetUser()
        {
            return user_;
        }

        /// <summary>
        /// Handles the Click event of the createBtn control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void createBtn_Click(object sender, EventArgs e)
        {
            nameTextBox.Text.Trim();    //Удаляем пробельные символы из начала и конца строки
            if ((nameTextBox.Text != String.Empty) && (passwTextBox.Text != String.Empty))
            {

                user_ = new User(nameTextBox.Text,passwTextBox.Text);//TODO: брать хэш пароля

                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }

        /// <summary>
        /// Handles the Click event of the cancelBtn control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void cancelBtn_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }
    }
}
